package org.example.leetcode;

import java.util.*;

/**
 * @author: lynn
 * @Descript:
 * @date: 2021/8/5 11:52
 * @version: 1.0
 */
public class LC49_1 {

    public List<List<String>> groupAnagrams(String[] strs) {
        Map<String,List<String>> map=new HashMap<>();
        for (int i = 0; i <strs.length ; i++) {
            String c=strs[i];
            char[] chars=c.toCharArray();
            List<String> tmp=new ArrayList<>();
            Arrays.sort(chars);
            String sortKey=String.valueOf(chars);
            if (map.get(sortKey)!=null){
                tmp= map.get(sortKey);
            }
            tmp.add(c);
            map.put(sortKey,tmp);
        }
        return new ArrayList<List<String>>(map.values());
    }
}
